# import re
# hand = open('../mbox-short.txt')
# for line in hand:
#     line = line.rstrip()
#     # if re.search('From:', line): # 寻找含有 某个词汇的行
#     #     print(line)
#
#     # if line.find('From:'):
#     # x = re.findall('^From .* [0-9][0-9]:', line) # 检索小时
#     # # x = re.findall('^From .* ([0-9][0-9]):', line) # 只返回小时 () 表示目标返回的内容
#     # if len(x) > 0:
#     #     print(x)
#     x = re.findall('^Details:.*rev=([0-9]+)', line) # Details: http://source.sakaiproject.org/viewsvn/?view=rev&rev=39772
#     if len(x) > 0:
#         print(x)



# import re
# hand = open('../mbox-short.txt')
# for line in hand:
#     line = line.rstrip()
#     # x = re.findall('\S+@\S+', line)
#     # x = re.findall('[a-zA-Z0-9]\S*@\S*[a-zA-Z]', line)
#     #
#     # if len(x) > 0:
#     #     print(x)
#
#     x = re.findall('(^X\S*): [0-9.]+', line) # ()
#     if len(x) > 0:
#         print(x)

fname = open('../mbox-short.txt','r')
counts = {}

for line in fname:
    line = line.rstrip()
    if line.startswith('From'):
        word = line.split(' ')
        if len(word) >= 6:
            time_ = word[6].split(':')[0]

            if time_ not in counts:
                counts[time_] = 1
            else:
                counts[time_] += 1

print(counts)